package com.example.design.shejimoshi.action.oberver;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者
 */
public class Observerable {
    private int state;

    private List<Observer> observers = new ArrayList<>();

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObervers();
    }

    void addObserver(Observer observer){
        observers.add(observer);
    }

    void notifyAllObervers(){
        for (Observer observer : observers) {
            observer.doEvent();
        }
    }

}
